package behavior.chain_responsibility;

public abstract class ChainHandler{

    protected final String PRINT_INFO="开始处理level%d的数据，打印出%s日志";

    protected ChainHandler(int level){
        this.level = level;
        this.nextHandler = null;
    }

    protected ChainHandler nextHandler;
    protected int level;

    public final void handle(Request req){
        if(req.getLevel() == this.level){
            this.doOperate(req);
        }else if(this.nextHandler != null){
            this.nextHandler.handle(req);
        }else{
            System.out.println("没有找到对应level的处理器. level="+ req.getLevel());
        }
    }
    public final ChainHandler next(ChainHandler next){
        this.nextHandler = next;
        return this.nextHandler;
    }
    protected abstract void doOperate(Request req);

}
